package ym.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ym.mapper.EnteralNutritionPlanMapper;
import ym.pojo.EnteralNutritionPlan;
import ym.service.EnteralNutritionPlanService;

import java.util.List;

@DubboService
public class EnteralNutritionPlanServiceImpl implements EnteralNutritionPlanService {
    @Autowired
    private EnteralNutritionPlanMapper enteralNutritionPlanMapper;

    @Override
    public void add(EnteralNutritionPlan enteralNutritionPlan) {
        enteralNutritionPlanMapper.insert(enteralNutritionPlan);
    }

    @Override
    public void update(EnteralNutritionPlan enteralNutritionPlan) {
        enteralNutritionPlanMapper.updateById(enteralNutritionPlan);
    }

    @Override
    public void delete(Integer id) {
        enteralNutritionPlanMapper.deleteById(id);
    }

    @Override
    public void deleteByNutritionPlanId(Integer nutritionPlanId) {
        QueryWrapper<EnteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        enteralNutritionPlanMapper.delete(queryWrapper);
    }

    @Override
    public EnteralNutritionPlan findById(Integer id) {
        return enteralNutritionPlanMapper.selectById(id);
    }

    @Override
    public List<EnteralNutritionPlan> findAll() {
        return enteralNutritionPlanMapper.selectList(null);
    }

    @Override
    public Page<EnteralNutritionPlan> search(String search, int page, int size) {
        QueryWrapper<EnteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        if (search != null) {

        }
        return enteralNutritionPlanMapper.selectPage(new Page(page, size), queryWrapper);
    }

    @Override
    public Page<EnteralNutritionPlan> searchByNutritionPlanId(Integer nutritionPlanId, String search, int page, int size) {
        QueryWrapper<EnteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        if (search != null) {
            queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        } else {
            queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        }
        return enteralNutritionPlanMapper.selectPage(new Page(page, size), queryWrapper);
    }
}
